package com.api.user.config;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Ipay88 {

    public static String Signature(String RefNo,String Amount,String Currency,String merchantKey ,String merchantCode ){
        StringBuilder stringBuilder = new StringBuilder("");
        stringBuilder.append(merchantKey);
        stringBuilder.append(merchantCode);
        stringBuilder.append(RefNo);
        stringBuilder.append(Amount.replace(".","").replaceAll(",",""));
        stringBuilder.append(Currency);
        System.out.println(stringBuilder.toString());
        try {
            MessageDigest md = MessageDigest.getInstance("SHA-256");
            md.update(stringBuilder.toString().getBytes());
            byte byteData[] = md.digest();
            StringBuffer sb = new StringBuffer();
            for (int i = 0; i < byteData.length; i++) {
                sb.append(Integer.toString((byteData[i] & 0xff) + 0x100, 16).substring(1));
            }
            return sb.toString();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return "";
    }
}
